new Vue({
    el: "#container",
    data() {
        return {
            //用户信息
            userinfo:{
                headImg:"https://img01.yzcdn.cn/vant/cat.jpeg",
                userName:"",
                userPhone:"",
            },
            //厂站列表
            stationList:[],
            //用户当前的场站信息
            originId:null,
            originName:null,
            //密码信息
            pwd:{
                old:"",
                new:"",
                sure:""
            }
        }
    },
    created() {
        var that = this;
        that.queryUserInfo();
        that.initOrigin();
    },
    methods: {
        /**初始化站点**/
        initOrigin(){
            var that = this;
            $.ajax({
                type: "post",
                url: '/sys_origin/query/user/origin',
                async: true,
                dataType: 'json',
                timeout: 30000,
                data: {type: 2, status: 0},
                success: function (res) {
                    if (res.code == 0) {
                        that.stationList = res.data;
                    } else {
                        //您未关联站点,请联系管理人员
                    }
                },
                error: function (res) {
                    // wapAlert(res.msg);
                    return;
                },
                complete: function (XMLHttpRequest, status) {
                    if (status == 'timeout') {
                        wapAlert('网络链接超时,请稍后再试');
                        return;
                    }
                }
            });
        },
        /*获取用户信息*/
        queryUserInfo(){
            var that = this;
            $.ajax({
                type: "GET",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url:"/user/center/queryUserInfo",
                data:{},
                success: function (res) {
                    if(res.code == 0){
                        // 设置信息
                        that.userinfo.userName = res.data.userName;
                        that.userinfo.userPhone = res.data.userPhone;
                        that.originId = res.data.originId;
                        that.originName = res.data.originName;
                    }else {
                        // 获取失败,弹出信息
                        vant.Toast(res.msg);
                    }
                },
                error : function() {

                }
            });
        },
        // 点击站点
        clickStation(){
            $('.TipsWindown').show();
        },
        // 点击站点选项
        clickStationItem(originId){
            var that = this;
            that.originId = originId;
        },
        // 选择站点
        confirmStation(){
            var that = this;
            var orgId = that.originId;
            if (isNull(orgId) || orgId == -1) {
                wapAlert("请选择站点！");
                return;
            }
            wapLoading.show();
            $.ajax({
                type: "POST",
                url: "/console/chose/station",
                async: true,
                dataType: 'json',
                timeout: 30000,
                data: {originId: orgId},
                success: function (res) {
                    wapLoading.hide();
                    if (res.code == 0) {
                        that.originId = res.data.originId;
                        that.originName = res.data.originName;
                        $('.TipsWindown').hide();
                    } else {
                        wapAlert(res.msg);
                        return;
                    }

                },
                error: function (res) {
                    // wapAlert('系统异常,请稍后再试');
                    wapLoading.hide();
                    return;
                },
                complete: function (XMLHttpRequest, status) {
                    if (status == 'timeout') {
                        wapAlert('网络链接超时,请稍后再试');
                        wapLoading.hide();
                        return;
                    }
                }
            });
        },
        //显示修改密码弹窗
        showPwdBox(){
            $('.mask').removeClass('dn');
            $('.update-pwd-box').removeClass('dn');
        },
        //取消修改密码弹窗
        cancelPwd(){
            $('.mask').addClass('dn');
            $('.update-pwd-box').addClass('dn');
        },
        //提交密码
        confirmPwd(){
            /*$('.mask').addClass('dn');
            $('.update-pwd-box').addClass('dn');*/
            var that = this;
            //获取密码信息
            //旧密码
            var oldPwd = that.pwd.old;
            //新密码
            var newPwd = that.pwd.new;
            //确认密码
            var surePwd = that.pwd.sure;
            if(isNull(oldPwd)){
                wapAlert('请输入旧密码');
                return;
            }
            if(isNull(newPwd)){
                wapAlert('请输入新密码');
                return;
            }
            if(isNull(surePwd)){
                wapAlert('请输入确认密码');
                return;
            }
            if(newPwd != surePwd){
                wapAlert('新密码确认密码不一致！');
                return;
            }
            $.ajax({
                type: "put",
                url: "/sys_user/update/password",
                async: true,
                dataType: 'json',
                data: {
                    oldPassword: oldPwd,
                    newPassword: newPwd
                },
                timeout: 30000,
                success: function(res) {
                    if(res.code == 0){
                        vant.Toast("修改成功！");
                    }else {
                        vant.Toast(res.data.msg);
                    }
                },
                error: function(res) {

                    return;
                }
            });
        },
        //点击弹幕操作
        mask(){
            $('.mask').addClass('dn');
            $('.update-pwd-box').addClass('dn');
        },
        //个人信息
        showUserInfo(){
            window.location.href="/cloud/user/center/info";
        }
    }
})
